﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Dropthings.DAL;

namespace Dropthings.Business.Facade
{
    partial class Facade
    {
        public DataSet GetECYearDatas(string identifyCode, int year)
        {
            DataSet Ds = new DataSet();
            DataTable dt = new DataTable();
            dt.Columns.Add("ReadingMonth", typeof(string));
            dt.Columns.Add("AmmeterMonthData", typeof(double));
            dt.Columns.Add("GasMonthData", typeof(double));
            for (int i = 1; i <= 12; i++)
            {
                DataRow dr = dt.NewRow();
                dr[0] = i;
                dr[1] = 0;
                dr[2] = 0;
                dt.Rows.Add(dr);
            }
            UQ_GetAmmeterECYearDatas query = new UQ_GetAmmeterECYearDatas(identifyCode, year);
            DataSet ammeter= query.ExecuteDataset();
            UQ_GetGasECYearDatas queryGas = new UQ_GetGasECYearDatas(identifyCode, year);
            DataSet gas = queryGas.ExecuteDataset();
            int index = 0;
            if (ammeter != null && ammeter.Tables.Count > 0 && ammeter.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ammeter.Tables[0].Rows)
                {
                    index=Convert.ToInt32(dr[0]) - 1;
                    dt.Rows[index][1] = dr[1];
                }
            }
            if (gas != null && gas.Tables.Count > 0 && gas.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in gas.Tables[0].Rows)
                {
                    index = Convert.ToInt32(dr[0]) - 1;
                    dt.Rows[index][2] = dr[1];
                }
            }
            Ds.Tables.Add(dt);
            return Ds;
        }
    }
}
